﻿using System.Linq;
using System.Web.Mvc;
using FinancePortal.Business.Infraestructure;
using FinancePortal.Domain.Enum;
using FinancePortal.Business.Repository;
using System.Collections.Generic;
using POC_Citi.Web.Controllers;
using System.IO;

namespace FinancePortal.Controllers
{
    [Permission]
    public class HomeController : Controller
    {
        private readonly IActivityScheduleRepository _activityResourceRepository;

        public HomeController(IActivityScheduleRepository activityResourceRepository)
        {
            _activityResourceRepository = activityResourceRepository;
        }

        public ActionResult Index()
        {
            //var service = new EmailService();
            //var dest = new List<string> { "brunorf@imcla.lac.nsroot.net" };
            //service.EnviarEmail(dest, "AAA", "AAAA");

            ViewBag.Message = "Welcome to O&T Finance Portal.";
            var activityList = _activityResourceRepository.GetAll().Take(5).
                OrderByDescending(a => a.ToDate).ToList();

            return View(activityList);
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult DownloadDb()
        {
            var fileStream = System.IO.File.ReadAllBytes(Url.Content("~/TestData/TestDB.db"));
            var mimeType = "";
            var fileDownloadName = "TestDb.db";
            return File(fileStream, mimeType, fileDownloadName);

        }
    }
}
